package lab6;
/**
 * <p>Title: MathProblem class - An example of double-precision computations that can "fail"</p>
 * <p>Description: CS 235 Lab #6</p>
 * @author A Varghese
 * @email  anthony.varghese@uwrf.edu
 * @date   September 21st 2013
 * @team   none
 * 
 */

import java.util.Scanner;

class MyMath{
	public double compute(double x){
		double y = 1.0 + x;
		return Math.sqrt( 1/ y );
	}
}

public class MathProblem {
	public static void main(String[] args) {
		Scanner console = new Scanner( System.in );
		MyMath m = new MyMath();
		
		System.out.println("This program will compute a function for a range of values that you specify\n");
		System.out.print(" Please enter a valid double-precision number: " );
		final double user_input1 = console.nextDouble();
		System.out.print(" OK, thanks, now please enter a second double-precision number: " );
		final double user_input2 = console.nextDouble();
		console.close();
		
		final int iterations = 20;
		final double increment = (user_input2 - user_input1)/iterations;
		
		for (int i=0; i<=iterations; i++) {
			final double testvalue = user_input1 + i*increment;
			final double result = m.compute( testvalue ); 
			System.out.println("  " + testvalue + " -->  " + result );
		}
		System.out.println("Done!");
	}
}
